package com.sinai.mshab.client.ui.pages;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.sinai.mshab.client.ui.basic.Warning;
import com.sinai.mshab.client.util.Util;

public class SaveButton extends SidePanelButton implements SidePanelItem {

	/**
	 * {@link PageContainer} which is told to save, i.e. the one where the
	 * SaveButton is added.
	 */
	private PageContainer savingContainer;

	/**
	 * The message shown after saving. The default is {@value saveMessage}
	 */
	private String saveMessage = "Record Saved.";

	/**
	 * Creates a new <code>SaveButton</code> with showing the text "Save" and
	 * putting a "Saved" notice at the top of the Page when pressed.
	 * 
	 * @param saving
	 *            the container that we tell to save.
	 */
	public SaveButton(PageContainer savingContainer) {
		super("Save");
		this.savingContainer = savingContainer;

		// add a click listener.
		addClickListener(new ClickListener() {

			public void onClick(Widget sender) {
				save();
			}
		});
	}

	private void save() {
		savingContainer.submitAll();

		Warning saveWindow = new Warning(saveMessage, 0, 0);
		saveWindow.setTitle("Saved");
	}
}
